<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="http://123.207.19.115:8888/layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">版块名称</label>
        <div class="layui-input-block" style="width: 50%">
            <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">版主名称</label>
        <div class="layui-input-block" style="width: 50%">
            <select name="uid" id="nickname" lay-verify="required" lay-search="">
                <option value="">直接选择或搜索选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
        </div>
    </div>
</form>
<script src="http://123.207.19.115:8888/vue/vue.js"></script>
<script src="http://123.207.19.115:8888/vue/axios.js"></script>
<script src="http://123.207.19.115:8888/jquery/jquery-3.3.1.min.js"></script>
<script src="http://123.207.19.115:8888/layui/layui.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        $.ajax({
            type:"GET",
            url:"/admin/user/by/nouser/list",
            async:false,
            success:function (data) {
                for(var i = 0;i<data.data.length;i++){
                    var val = data.data[i].nickname;
                    var id = data.data[i].id;
                    var opt = "<option value='"+ id +"'>"+ val +"</option>"
                    $("#nickname").append(opt);
                    form.render();
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var da = data.field;
            if(da.name != "")
            {
                $.ajax({
                    type:"PUT",
                    url:"/admin/forum/admin/add",
                    data:{"name":da.name,"uid":da.uid},
                    async:false,
                    success:function (data) {
                        if(data.code !== null){
                            layer.alert('添加成功！')
                        }else {
                            layer.alert('添加失败！')
                        }
                    }
                });
            }else {
                layer.alert('版块名称不可为空！')
            }
            return false;
        });
    });
</script>
<script>
</script>
</body>
</html>